package com.applet.applet_shangcheng.dao;

import com.applet.applet_shangcheng.entity.Address;
import com.applet.applet_shangcheng.entity.Admin;
import com.applet.applet_shangcheng.entity.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select({
            "select user_id from tb_user where code=#{code}"
    })
    String selectCode(@Param("code") String code);

    @Update({
            "update tb_user set code=#{code} where user_id =#{userId}"
    })
    void createCode(@Param("userId") String userId, @Param("code") String code);

    @Select({
            "select id,user_id ,username,password,image,code,create_code,number,balance,integral,money,address,phone,age,birthday,hobby,position,professional,email,qq,the_chool,create_time,status from tb_user where user_id=#{userId} "
    })
    User getUser(@Param("userId") String userId);

    @Select({
            "select id,user_id ,username,password,image,code,create_code,number,balance,integral,money,address,phone,age,birthday,hobby,position,professional,email,qq,the_chool,create_time,status from tb_user"
    })
    List<User> getUserList();

    @Update({
            "update tb_user set address=#{date},phone=#{phone}where username=#{username} "
    })
    void updateDefaultValue(@Param("username") String username, @Param("date") String date, @Param("alias") String phone);

    @Update({
            "update tb_user set integral=integral+#{integral} where user_id =#{userId}"
    })
    void addIntrgral(@Param("integral") int integral, @Param("userId") int userId);

    @Update({
            "update tb_user set money=money+#{money} where user_id =#{userId}"
    })
    void addMoney1(@Param("money") double money, @Param("userId") int userId);

    @Select({
            "select id,user_id ,username,password,image,code,create_code,number,balance,integral,money,address,phone,age,birthday,hobby,position,professional,email,qq,the_chool,create_time,status from tb_user where username=#{username} "
    })
    User selectByName(String username);

    Page<User> findAll1(String queryString);

    Page<User> findAllAdmin(String queryString);

    @Select({
            "select id,user_id ,username,password from tb_user where user_id=#{userId} "
    })
    User selectUserId(@Param("userId") String userId);

    @Update({
            "update tb_user set image=#{image},code=#{code},create_code=#{createCode},number=#{number},balance=#{balance},integral=#{integral},money=#{money},address=#{address},phone=#{phone},age=#{age},birthday=#{birthday},hobby=#{hobby},position=#{position},professional=#{professional},email=#{email},qq=#{qq},the_chool=#{theChool},create_time=#{createTime} where id = #{id}"
    })
    int updateUser(User user);

    @Insert({
            "insert into tb_user (user_id,username,password,image,create_time,status) values (#{userId},#{username},#{password},#{image},#{createTime},#{status})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    @Select({
            "select * from tb_admin where username=#{username}"
    })
    Admin findUserByAdmin(@Param("username") String username);

    @Update({
            "update tb_admin set username=#{username},password=#{password},image=#{image},status=#{status} where username=#{username}"
    })
    int updateAdmin(Admin admin);

    @Insert({
            "insert into tb_admin (username,password,image,status) values (#{username},#{password},#{image},#{status})"
    })
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int insertAdmin(Admin admin);

    @Select({
            "select * from tb_admin where username =#{username}"
    })
    Admin getAdmin(@Param("username") String username);

    @Delete({
            "delete from tb_admin where username =#{username}"
    })
    int deleteAdmin(@Param("username") String username);
    @Update({
            "update tb_user set integral = integral+ #{countSun} where code =#{code}"
    })
    void save(@Param("code")String code,@Param("countSun") int countSun);


    @Select({
            "select count(*) from tb_user where create_time <=#{month}"
    })
    int getTime(@Param("month")String month);
}
